package utils
{
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.DropShadowFilter;
	

	/**
	 *	创建简单滤镜的工具类 
	 * @author Roland
	 * 
	 */
	public class FilterUtil
	{
		public function FilterUtil()
		{
		}
		
		
		/**
		 *	根据参数创建颜色矩阵滤镜
		 * @param brightness 亮度
		 * @param contrast 对比度
		 * @param saturation 饱和度
		 * @param hue 色相
		 * @return 
		 * 
		 */
		public static function createColorMatrixFilter(brightness:Number,contrast:Number,saturation:Number,hue:Number):ColorMatrixFilter
		{
			var $m:Array = new Array(20);
			var matrix:Array = new ColorMatrix();
			matrix.adjustColor(brightness,contrast,saturation,hue);
			var c:ColorMatrixFilter = new ColorMatrixFilter(matrix);
			return c;
		}

		/**
		 * 建立一个彩色投影滤镜数组
		 * @param color 投影颜色
		 * @param strength 投影强度
		 * @param alpha 投影alpha
		 * @param angle 投影角度
		 * @param distance 投影距离
		 * @param blurX 模糊x
		 * @param blurY 模糊y
		 * @return [指定颜色的投影滤镜]
		 * 
		 */
		public static function createDSFilter(color:uint=0x003366,strength:Number = 6.0,alpha:Number = 1,angle:Number = 0,distance:Number = 0.0,blurX:Number =  5.0,blurY:Number = 5.0):Array
		{
			var inner:Boolean = false;
			var knockout:Boolean = false;
			var quality:Number = 1;
			var hideObject:Boolean = false;
			return [new DropShadowFilter(distance,angle,color,alpha,blurX,blurY,strength,quality,inner,knockout,hideObject)];
		}
		
		/**
		 *	对显示对象的所有子对象单独设置滤镜 
		 * @param m 要设置滤镜的显示对象
		 * @param filters 滤镜数组
		 * 
		 */
		public static function setAllChildFilter(m:*,filters:Array):void
		{
			if(m is DisplayObjectContainer)
			{
				for (var i:int = 0; i < m.numChildren; i++) {
					var c:* = m.getChildAt(i);
					setAllChildFilter(c, filters);
				}
			}else if(m.hasOwnProperty("filters")){
				m.filters = filters;
			}
		}
	}
}